package com.itheima.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.util.unit.DataSize;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

/**
 * className: ServerConfig
 * description:
 * date: 2023/3/1 0001-PM 11:02:10
 * <p>
 * project: springboot
 * package: com.itheima.config
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
// @Component
@Data
@ConfigurationProperties(prefix = "servers")
// 2.开启对当前 bean 的属性注入校验
@Validated
public class ServerConfig {
    private String ipAddress;
    @Max(value = 8888, message = "最大值不能超过888")
    @Min(value = 202, message = "最小值不能低于202")
    private int port;
    private long timeout;
    @DurationUnit(ChronoUnit.HOURS)
    private Duration serverTimeout;
    // @DataSizeUnit(DataUnit.MEGABYTES)
    private DataSize dataSize;
}
